// pages/EditProblem/index.js
import {
  HTTP
} from '../../utils/http.js'
let Myhttp = new HTTP()

Page({
 

  /**
   * 页面的初始数据
   */
  data: {
    return_index:false,
    qid: '',
    questionnaire: [],
    answer_status:0,
    is_self:0,

  },
  
  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    if (options.return_index) {
      this.setData({
        return_index: true
      })
    }else{
      this.setData({
        return_index: false
      })
    }
    // console.log(options)
    let datas = JSON.parse(options.datas)
    let questionnaire = `questionnaire[${0}]`
    let that = this
    this.setData({
      qid: options.datas
    })
   // console.log(options.datas)
    Myhttp.request({
      url: '/questionnaire/questionnaire/questionnaireInfo',
      method: 'POST',
      data: {
        qid: this.data.qid
      },
      success: (res) => {
        // console.log(res)
        let data = res.data.data
        that.setData({
          status: data.status,
          questionnaire: data,
          is_self: data.is_self,
          answer_status: data.answer_status,
        })
        
      }
    })
  },
  CheckResults:function(e){
    // console.log(this.data.is_self)
    let is_self = this.data.is_self
    let id = this.data.qid 
    Myhttp.jump({
      url: `/pages/AnswerResult/index?datas=${id}&&is_self=${is_self}`
    })
  },
  answerclick: function () {
    let id = this.data.qid
    //console.log(newdatas)
    wx.navigateTo({
      url: `/pages/StartAnswer/AnswerDtails/index?datas=${id}`
    })
  },
  // EditAnswer:function(e){
  //   Myhttp.jump({
  //     url: "url: `/pages/PublishQuestionnaire/EditProblem/index?qid=${this.data.qid}`",
  //     success: (res) => {
  //       console.log(res)
  //     }
  //    })
  // },
  startAnswerOver:function(){
    wx.navigateBack({
      // url: '/pages/personal/personal_details/index'
      delta:1
    })
  },
  
  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {
    let that = this
    Myhttp.request({
      url: '/questionnaire/questionnaire/questionnaireInfo',
      method: 'POST',
      data: {
        qid: this.data.qid
      },
      success: (res) => {
        // console.log(res)
        let data = res.data.data
        data.url = data.url_domin + data.cover
        that.setData({
          questionnaire: data,
          is_self: data.is_self,
          answer_status: data.answer_status
        })
      }
    })
    wx.stopPullDownRefresh() //停止下拉刷新
  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {
    
  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {
    return {
      path: `/pages/EditFinal/index?datas=${this.data.qid}&&return_index=${'1'}`
    }
  }
})